﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Helper
{
    public class XmlHelper
    {
        public static void UpdataNodeValue(string filename, string xpath, object value)
        {
            try
            {
                XmlDocument _xmlDoc = new XmlDocument();
                _xmlDoc.Load(filename);
                XmlNode xn = _xmlDoc.SelectSingleNode(xpath);
                xn.Attributes["value"].Value = value.ToString();
                _xmlDoc.Save(filename);
            }
            catch (Exception) { }
        }

        public static string GetNodeValue(string filename, string xpath)
        {
            try
            {
                XmlDocument _xmlDoc = new XmlDocument();
                _xmlDoc.Load(filename);
                return _xmlDoc.SelectSingleNode(xpath).Value;
            }
            catch (Exception)
            {
                return null;
            }
        }
    }
}
